package com.badlgic.androidgames;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.SpriteBackground;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;

public class GameScreen extends BaseGameActivity{

	private static final int CAMERA_WIDTH = 768;
	private static final int CAMERA_HEIGHT = 1024;
	
	protected Camera mCamera;
	
	private Scene scene;
	
	private BitmapTextureAtlas mBackgroundBitmapTextureAtlas;
	private BitmapTextureAtlas mBoardBitmapTextureAtlas;
	
	protected TextureRegion mBackgroundTextureRegion;
	protected TextureRegion mBoardTextureRegion;
	
	@Override
	public Engine onLoadEngine() {
		this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
		return new Engine(new EngineOptions(true, ScreenOrientation.PORTRAIT, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
	}

	@Override
	public void onLoadResources() {
		this.mBackgroundBitmapTextureAtlas = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.mBackgroundTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBackgroundBitmapTextureAtlas, this, "gfx/background.jpg", 0, 0);
		
		this.mBoardBitmapTextureAtlas = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		this.mBoardTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBoardBitmapTextureAtlas, this, "gfx/bg_game.png", 0, 0);
		
		this.mEngine.getTextureManager().loadTextures(this.mBackgroundBitmapTextureAtlas, this.mBoardBitmapTextureAtlas);
	}

	@Override
	public Scene onLoadScene() {
		this.mEngine.registerUpdateHandler(new FPSLogger());
		
		scene = new Scene();
		
		Sprite background = new Sprite(0, 0, mBackgroundTextureRegion);
		Sprite board = new Sprite(0, 130, mBoardTextureRegion);
		
		scene.setBackground(new SpriteBackground(background));
		scene.attachChild(board);
		return scene;
	}

	@Override
	public void onLoadComplete() {
		
	}

}
